import numpy as np
import matplotlib.pyplot as plt

# 创建一个包含100个随机数的数组
data = np.random.rand(100)

# 计算均值、方差和标准差
mean = np.mean(data)
variance = np.var(data)
std_dev = np.std(data)

# 绘制图形
plt.figure(figsize=(10,6))
plt.plot([0, 100], [mean, mean], 'r--', linewidth=2)
plt.fill_between([0, 100], [mean - std_dev, mean - std_dev], [mean + std_dev, mean + std_dev], alpha=0.2)
plt.plot([0, 100], [mean - std_dev, mean + std_dev], 'g--', linewidth=1)
plt.scatter(data, np.zeros_like(data), c='b')
plt.title('均值、方差和标准差')
plt.xlabel('值')
plt.ylabel('统计量')
plt.grid(True)
plt.show()
